# coding:utf-8

import os

from celery.schedules import crontab


CELERY_TIMEZONE = 'Asia/Shanghai'
# BROKER_URL = 'amqp://localhost:5672//'
BROKER_URL = os.environ.get('celery_broker_url') or 'redis://localhost:6379/4'
CELERY_RESULT_BACKEND = os.environ.get(
    'celery_result_backend') or 'redis://localhost:6379/3'


CELERYBEAT_SCHEDULE = {
    'invite_improve': {
        'task': 'invite_improve',
        'schedule': crontab('*/10'),
        # 'schedule': 60,  # 每1分钟执行一次, 做调试用
    },
    'sync_binded_wx_user': {
        'task': 'sync_binded_wx_user',
        'schedule': crontab(hour=2, minute=0)
    },
    # NOTE by chenhj, 每小时执行一次
    'apply_im_token': {
        'task': 'generate_im_token',
        'schedule': crontab(hour='*', minute=0),
        # 'schedule': 60
    },
    'opc_day_stat': {
        'task': 'opc_day_stat',
        'schedule': crontab(hour=0, minute=30),
        # 'schedule': 60
    },
    'invite_msg_task': {
        'task': 'invite_msg_task',
        'schedule': crontab(hour=10, minute=0),
        # 'schedule': 60
    },
    # NOTE by zhouhl，定时解绑7天未使用的虚拟号关系
    'unbind_expired_virtual_number': {
        'task': 'unbind_expired_virtual_number',
        'schedule': crontab(hour=0, minute=30),
    },

    # NOTE by zhouhl，定时将10天前发布的项目状态调整为“圆满完成”
    'set_demand_done': {
        'task': 'set_demand_done',
        'schedule': crontab(hour=0, minute=30),
    },

    'set_seven_days_marketing_sms_done': {
        'task': 'set_seven_days_marketing_sms_done',
        'schedule': crontab(hour=0, minute=30),
    },
    'voucher_expired_notify': {
        'task': 'voucher_expired_notify',
        'schedule': crontab(hour=10, minute=0)
    },
    'voucher_expired_task': {
        'task': 'voucher_expired_task',
        'schedule': crontab(hour=0, minute=0)
    }
}

# 25 小时过期
BROKER_TRANSPORT_OPTIONS = {'visibility_timeout': 25 * 60 * 60}

# 每个worker执行了多少任务就会死掉
CELERYD_MAX_TASKS_PER_CHILD = 40

